package com.example.demo;

import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.jackson.JsonObjectSerializer;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

/**
 * jedis 事务
 */
public class TestTX {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1",6379);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","cwy");
        jsonObject.put("age",18);
        Transaction multi = jedis.multi();
        try {
            multi.set("user",jsonObject.toJSONString());
            System.out.println(1);
            multi.exec();
        }catch (Exception e){
            System.out.println(e.getMessage());
            multi.discard();
        }finally {
            jedis.close();
        }
    }
}
